package com.yangfei.mystudy1020.animation.AnimActivity;

import android.os.Bundle;
import android.util.Log;

import com.facebook.rebound.SimpleSpringListener;
import com.facebook.rebound.Spring;
import com.facebook.rebound.SpringConfig;
import com.facebook.rebound.SpringSystem;
import com.facebook.rebound.SpringUtil;
import com.nineoldandroids.view.ViewHelper;

public class SpringBasicActivity extends BaseAnimationActivity {
    SpringSystem mSpringSystem;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStartAnimation() {
        mSpringSystem = SpringSystem.create();
        Spring spring = mSpringSystem
                .createSpring()
                .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(100, 0.2))
                .addListener(new SimpleSpringListener() {
                    @Override
                    public void onSpringUpdate(Spring spring) {
                        float value = (float) spring.getCurrentValue();
                        float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
                        Log.d("SpringBasicActivity", "value = " + value+" mappedValue="+mappedValue+" Velocity = "+spring.getVelocity());
                        ViewHelper.setScaleX(doge, value);
                        ViewHelper.setScaleY(doge, value);
                    }
                });
        spring.setEndValue(3);
    }
}
